#include "stdafx.h"
#include "Task.h"
#include "GameApp.h"


Task::Task()
{
	m_State = INACTIVE;
	m_IsSystemTask = false;
}

Task::~Task()
{
	ASSERT(m_State == INACTIVE);
}

void Task::Start()
{
	switch (m_State)
	{
	case INACTIVE:
		OnStart();
		m_State = ACTIVE;
		g_TaskService->OnActivate(this);
		break;

	case ACTIVE:
		break;

	case PAUSED:
		OnResume();
		m_State = ACTIVE;
		break;

	case STOPPED:
		break;
	}
}

void Task::Stop()
{
	switch (m_State)
	{
	case INACTIVE:
		break;

	case ACTIVE:
		m_State = STOPPED;
		OnStop();
		m_State = INACTIVE;
		g_TaskService->OnDeactivate(this);
		break;
	
	case PAUSED:
		OnResume();
		m_State = STOPPED;
		OnStop();
		m_State = INACTIVE;
		g_TaskService->OnDeactivate(this);
		break;

	case STOPPED:
		break;
	}
}

void Task::Pause()
{
	switch (m_State)
	{
	case INACTIVE:
		OnStart();
		m_State = PAUSED;
		OnPause();
		g_TaskService->OnActivate(this);
		break;

	case ACTIVE:
		m_State = PAUSED;
		OnPause();
		break;

	case PAUSED:
		break;

	case STOPPED:
		break;
	}
}

void Task::Send( Event* evt )
{
	switch (m_State)
	{
	case ACTIVE:
		OnEvent(evt);
		return;
	}
}